#include <bits/stdc++.h>
using namespace std ;

const int maxn = 2e5 + 5 ;
int n, a[maxn], color[maxn], c[maxn] ;
long long ans = 0 ; bool flag = true ;

inline long long check() {
	for (int i = 2; i <= n; ++ i)
		for (int j = i - 1; j >= 1; -- j)
			if (color[i] == color[j]) {
				if (a[i] == a[j]) c[i] = a[i] ;
				else break ;
			}
				
	long long ch = 0 ;
	for (int i = 1; i <= n; ++ i)
		ch += c[i] ;
	
	return ch ;
}

inline long long dfs(int dep) {
	
	if (dep == n + 1) {
		ans = max(ans, check()) ;
		memset(c, 0, sizeof(c)) ;
		return ans ;
	}
	
	color[dep] = 1 ; dfs(dep + 1) ;
	color[dep] = 2 ; dfs(dep + 1) ;
	
}

inline void solve() {
	
	ans = 0 ;
	memset(color, 0, sizeof(color)) ;
	memset(c, 0, sizeof(c)) ;
	
	scanf("%d", &n) ;
	for (int i = 1; i <= n; ++ i)
		scanf("%d", &a[i]) ;
		
	printf("%lld\n", dfs(1)) ;
	
}

int main() {

    freopen("color.in", "r", stdin) ;
    freopen("color.out", "w", stdout) ;

	int T ; scanf("%d", &T) ;
	while (T--) solve() ;
	
    return 0 ;
}	// 20 pts
